package com.ncp.servlet.product;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.comment.CommentCl;
import com.ncp.model.biz.comment.CommentScoCl;
import com.ncp.model.biz.product.ManageFrontProductBiz;
import com.ncp.model.entity.comment.ProductComment;
import com.ncp.model.entity.product.CommentBean;
import com.ncp.model.entity.product.ImgsUploadBean;
import com.ncp.model.entity.product.ProductBasicBean;
import com.ncp.model.entity.product.ProductDetailBean;

public class ManageFrontzDetailProductServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		ManageFrontProductBiz mfpb = new ManageFrontProductBiz();
		
			 int ProductID = Integer.parseInt(request.getParameter("ProductID"));
			 List<ProductDetailBean> listdetail=mfpb.getProductDetail(ProductID);
			
			 int nowPage=1;
			

			 String p=request.getParameter("page");
			 if(p!=null&&!p.equals("")){
			 	nowPage=Integer.parseInt(p);
			 }
			 
			 CommentCl cc=new CommentCl();
			 int PageCount=cc.getCount(ProductID);
			 int Numbers = cc.getCommentNum(ProductID); 
			 CommentScoCl csc=new CommentScoCl();
			 float star=csc.formatFloat(csc.getAvgSco(ProductID));
			 ArrayList<ProductComment> list=cc.getCommentInfo(ProductID,nowPage);
			 request.setAttribute("listdetail", listdetail);
			 
			 CommentBean cb = new CommentBean();
			 cb.setCommentNumber(Numbers);
			 cb.setPagecount(PageCount);
			 cb.setStar(star);
			 request.setAttribute("list", list);
			 request.setAttribute("cb", cb);
			 request.setAttribute("ProductID",ProductID+"");

			 request.getRequestDispatcher("pages/comment/detail.jsp").forward(request,response);
			 
	}

}
